package com.flea.hclv.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSON;
import com.flea.hclv.model.entity.HDriverLicense;
import com.flea.hclv.service.HDriverLicenseService;
import com.flea.system.platform.session.FleaOrgUtils;
import com.flea.system.utils.ControllerResult;

/**
 * @program: project
 * @description: 驾驶证
 * @author: shiliqiang
 * @create: 2018-09-26 20:43
 * @version: 1.0
 */
@Controller
@RequestMapping("/flea/hclv/driver/license/")
public class HDriverLicenseController {

    @Autowired
    private HDriverLicenseService hDriverLicenseService;

    @RequestMapping("saveOrUpdate")
    public void saveOrUpdate(HttpServletRequest request, HttpServletResponse response){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        String model = request.getParameter("model");
        HDriverLicense hDriverLicense = JSON.parseObject(model,HDriverLicense.class);
        boolean result = hDriverLicenseService.saveOrUpdate(userId,hDriverLicense);
        ControllerResult cResult = new ControllerResult(true, "操作成功", result);
        cResult.WriteToPage(response);
    }
    @RequestMapping("selectByDriverId")
    public void selectByDriverId(HttpServletRequest request, HttpServletResponse response,
                                 @RequestParam("driverId")String driverId){
        HDriverLicense hDriverLicense = hDriverLicenseService.selectByDriverId(driverId);
        ControllerResult cResult = new ControllerResult();
        cResult.Write(response,hDriverLicense);
    }
    @RequestMapping("deleteByIds")
    public void deleteByIds(HttpServletRequest request, HttpServletResponse response, @RequestParam("ids")String ids){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        List<String> idList = JSON.parseArray(ids,String.class);
        boolean result = hDriverLicenseService.deleteByIds(userId,idList);
        ControllerResult cResult = new ControllerResult(true, "操作成功", result);
        cResult.WriteToPage(response);
    }
}
